#pragma once
#include"RBTree.h"

namespace bit
{
	template<class K>
	class set
	{
		struct SetKeyofT
		{
			const K& operator()(const K& key)
			{
				return key;
			}
		};
	public:
		typedef typename RBTree<K, K, SetKeyofT>::const_iterator iterator;
		typedef typename RBTree<K, K, SetKeyofT>::const_iterator const_iterator;
		typedef typename RBTree<K, K, SetKeyofT>::const_reverse_iterator reverse_iterator;
		typedef typename RBTree<K, K, SetKeyofT>::const_reverse_iterator const_reverse_iterator;


		pair<iterator,bool> Insert(const K& key)
		{
			pair<typename RBTree<K, K, SetKeyofT>::iterator, bool> ret = _t.Insert(key);
			return pair<iterator, bool>(ret.first, ret.second);
		}

		iterator begin() const
		{
			return _t.begin();
		}

		iterator end() const
		{
			return _t.end();
		}
		
		reverse_iterator rbegin() const
		{
			return _t.rbegin();
		}

		reverse_iterator rend() const
		{
			return _t.rend();
		}

	private:
		RBTree<K, K,SetKeyofT> _t;
	};


	void testsSet()
	{
		//int arr[] = { 16, 3, 7, 11, 9, 26, 18, 14, 15};

		//int arr[]={4, 2, 6, 1, 3, 5, 15, 7, 16, 14};
		//int arr[] = { 5,3,7,1,4,6,8,0,2,9 };
		int arr[] = { 20,3,44,5,6,75,8,19,60,50,12,1 };
		set<int> st;
		for (auto& e : arr)
		{
			st.Insert(e);
		}

		set<int>::iterator it = st.begin();
		while (it != st.end())
		{
			//(*it)++;
			cout << *it << " ";
			++it;
		}
		cout << endl;

		set<int>::reverse_iterator rit = st.rbegin();
		while (rit != st.rend())
		{
			cout << *rit << " ";
			++rit;
		}
		cout << endl;
	}
}